from volcengine.auth.SignerV4 import SignerV4
from volcengine.auth.SignParam import SignParam
from volcengine.Credentials import Credentials
from collections import OrderedDict
import requests
import json
# Request configuration
method = 'POST'
host = 'agent_openapi.swjtu.edu.cn'
path = '/'
action = 'ListAppCenter'
version = '2023-08-01'
ak = 'HIAKZDNiNWNHOVlSTGFqd2FLRE1iaHNpbTdvNjhmMzRhbzA'
sk = 'AO1Ou/9nF39RbgSIEHj9MW9t+whcQ+a2p9vv9mNEIH9OtLtEz9H2fSIaQA=='
region = 'cn-north-1'
service = 'app'
# Required parameters
workspace_id = 'personal-d2sekbnn4eebed08tnig' # Replace with actual WorkspaceID
# app_id='cvrn8avbqin51rv6rsbg' # Replace with actual app_id
if __name__ == '__main__':
    # Create signature object
    sign = SignerV4()
    # Configure signature parameters
    param = SignParam()
    param.path = path

    param.method = method
    param.host = host
    # Set query parameters
    query = OrderedDict()
    query['Action'] = action
    query['Version'] = version
    query['X-Account-Id'] = "1000000000"
    param.query = query
    # Set request headers
    header = OrderedDict()
    header['Host'] = host
    header['Content-Type'] = 'application/json' # Add Content-Type header
    param.header_list = header
    param.headers = header
    # Set request body
    body = {
        # "WorkspaceID": workspace_id,
        # "DatasetId":"01979c34-06bf-78fa-8e8c-af0be44564cc"
    }
    param.body = json.dumps(body)
    # Generate signed URL
    cren = Credentials(ak, sk, service, region)
    sign.sign(param, cren)
    # Send request
    url = f"https://{host}{path}?Action={action}&Version={version}&X-Account-Id=1000000000"
    print(url)
    headers = {"Content-Type": "application/json"}
    #response = requests.post(url, headers=headers, cookies=cookies,
    data=param.body
    response = requests.post(url, headers=param.headers, data=param.body, verify=False)
    print(f"headers: {dict(param.headers)}")
    print(response)
    # Output result
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.text}")